/*     */ package com.qmsk.business.wxdownload.controller;
/*     */ 
/*     */ import com.qmsk.business.member.custIntratnchannel.dao.CustIntratnChannelDAO;
/*     */ import com.qmsk.business.weixin.customMenu.customer.CustomerInfo;
/*     */ import com.qmsk.business.weixin.customMenu.weiXinUtil.WeiXinUtil;
/*     */ import com.qmsk.business.weixin.customMenu.wxMapUtils.WxMapUtils;
/*     */ import com.qmsk.business.wxdownload.bean.MsgType;
/*     */ import com.qmsk.business.wxdownload.dao.WxCustomerReplayMsgDAO;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.util.Date;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"media"})
/*     */ public class WxDownLoad
/*     */ {
/*  37 */   private static final Logger logger = Logger.getLogger(WxDownLoad.class);
/*     */ 
/*     */   @Autowired
/*     */   private WxCustomerReplayMsgDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private CustIntratnChannelDAO custIntratnChannelDAO;
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"download/media/openId/{openId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void downLoadMedia(@PathVariable("openId") String openId, HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/*  54 */       String mId = RequestUtils.getString(request, "mId");
/*  55 */       String fomat = RequestUtils.getString(request, "fomat");
/*  56 */       String msgType = RequestUtils.getString(request, "type");
/*     */ 
/*  58 */       logger.info("mId:" + mId);
/*  59 */       logger.info("fomat:" + fomat);
/*  60 */       logger.info("msgType:" + msgType);
/*  61 */       String openName = null;
/*     */       try
/*     */       {
/*  64 */         CustomerInfo custInfo = WxMapUtils.getCustInfoOfOpenId(openId);
/*  65 */         openName = custInfo.getNickname();
/*  66 */         logger.info("openName:" + openName);
/*     */       } catch (Exception e) {
/*  68 */         logger.error("获取用户昵称出错，openId:" + openId);
/*  69 */         throw new Exception("获取用户昵称出错，openId:" + openId);
/*     */       }
/*  71 */       GsonHeadOneRow row = null;
/*  72 */       if (StringUtils.isNotEmpty(openId)) {
/*  73 */         row = this.custIntratnChannelDAO.selectSqlOfOpenIdAndMaxTime(openId);
/*     */ 
/*  75 */         if ((row == null) || (row.getDataLength() <= 0)) {
/*  76 */           ResponseUtils.setSuccessResponse(response);
/*  77 */           logger.info("当前不存在互动！");
/*  78 */           return;
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/*  83 */       String url = null;
/*  84 */       if (fomat != null) {
/*  85 */         url = WeiXinUtil.http_get_wxDownload(msgType, fomat, mId);
/*  86 */         logger.info("url1:" + url);
/*     */       }
/*  88 */       if (StringUtils.isEmpty(url)) {
/*  89 */         url = WeiXinUtil.http_get_wxDownload(msgType, fomat, mId);
/*  90 */         logger.info("url2:" + url);
/*     */       }
/*  92 */       if ((url != null) && (openName != null) && (mId != null) && 
/*  93 */         (msgType != null)) {
/*  94 */         Integer channelId = (Integer)row.getValueOfName("channelId");
/*  95 */         Long id = (Long)row.getValueOfName("id");
/*  96 */         int type = MsgType.getTypeId(msgType).intValue();
/*     */ 
/*  98 */         GsonHeadOneRow g = new GsonHeadOneRow(new String[0], 
/*  99 */           new Object[0]);
/*     */ 
/* 101 */         Date date = new Date();
/* 102 */         g.addHeadData("OpenID", openId);
/* 103 */         g.addHeadData("OpenName", openName);
/* 104 */         g.addHeadData("msgTypId", Integer.valueOf(type));
/* 105 */         g.addHeadData("creatTime", date);
/* 106 */         g.addHeadData("channelId", channelId);
/* 107 */         switch (type)
/*     */         {
/*     */         case 2:
/* 109 */           g.addHeadData("imageMid", mId);
/* 110 */           g.addHeadData("imageUrl", url);
/* 111 */           break;
/*     */         case 5:
/* 116 */           g.addHeadData("voiceMId", mId);
/* 117 */           g.addHeadData("voiceUrl", url);
/* 118 */           break;
/*     */         case 3:
/* 121 */           g.addHeadData("linkUrl", url);
/* 122 */           break;
/*     */         case 4:
/* 125 */           throw new Exception("不支持地址信息类型");
/*     */         case 1:
/* 131 */           throw new Exception("不支持文本信息类型");
/*     */         default:
/* 134 */           throw new Exception("未找到信息类型");
/*     */         }
/*     */ 
/* 138 */         int n = this.dao.insertGsonHeadOneRow(g, "wx_customerreplymsg");
/* 139 */         if (n <= 0) {
/* 140 */           throw new Exception("添加数据到表 wx_customerreplymsg 失败！");
/*     */         }
/*     */ 
/* 143 */         n = this.custIntratnChannelDAO.updateIntratnTimeById(date, id);
/* 144 */         if (n > 0) {
/* 145 */           DbConnection.commit();
/*     */         } else {
/* 147 */           DbConnection.rollback();
/* 148 */           throw new Exception("更新 custIntratnChannel 表失败！date=" + 
/* 149 */             date + " id=" + id);
/*     */         }
/*     */ 
/* 152 */         ResponseUtils.setSuccessResponse(response);
/* 153 */         return; }
/* 154 */       logger.error("上传失败,存在空数据：openName=" + openName + " openId=" + 
/* 155 */         openId + " msgType=" + msgType + " url=" + url + 
/* 156 */         " mId=" + mId);
/*     */     }
/*     */     catch (Exception e) {
/* 159 */       DbConnection.rollback();
/* 160 */       logger.error("上传失败,事务异常:" + e.getMessage());
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"insert/sendtextInfo/openId/{openId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void sendtextInfo(@PathVariable("openId") String openId, HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/* 172 */       String content = RequestUtils.getString(request, "content");
/* 173 */       String msgType = RequestUtils.getString(request, "type");
/* 174 */       String openName = null;
/*     */       try {
/* 176 */         CustomerInfo custInfo = WxMapUtils.getCustInfoOfOpenId(openId);
/* 177 */         openName = custInfo.getNickname();
/*     */       } catch (Exception e) {
/* 179 */         logger.error("获取用户昵称出错，openId:" + openId);
/* 180 */         throw new Exception("获取用户昵称出错，openId:" + openId);
/*     */       }
/* 182 */       if ((openName != null) && (openId != null) && (msgType != null))
/*     */       {
/* 184 */         GsonHeadOneRow row = this.custIntratnChannelDAO
/* 185 */           .selectSqlOfOpenIdAndMaxTime(openId);
/*     */ 
/* 187 */         if ((row == null) || (row.getDataLength() <= 0)) {
/* 188 */           logger.info("当前不存在互动！");
/* 189 */           ResponseUtils.setSuccessResponse(response);
/* 190 */           return;
/*     */         }
/*     */ 
/* 193 */         Integer channelId = (Integer)row.getValueOfName("channelId");
/* 194 */         Long id = (Long)row.getValueOfName("id");
/*     */ 
/* 196 */         int type = MsgType.getTypeId(msgType).intValue();
/*     */ 
/* 198 */         GsonHeadOneRow g = new GsonHeadOneRow(new String[0], 
/* 199 */           new Object[0]);
/* 200 */         Date date = new Date();
/* 201 */         g.addHeadData("OpenID", openId);
/* 202 */         g.addHeadData("OpenName", openName);
/* 203 */         g.addHeadData("msgTypId", Integer.valueOf(type));
/* 204 */         g.addHeadData("creatTime", date);
/* 205 */         g.addHeadData("channelId", channelId);
/* 206 */         if (type == 1)
/* 207 */           g.addHeadData("content", content);
/*     */         else {
/* 209 */           throw new Exception("信息类型不是文本！");
/*     */         }
/*     */ 
/* 213 */         int n = this.dao.insertGsonHeadOneRow(g, "wx_customerreplymsg");
/* 214 */         if (n <= 0) {
/* 215 */           throw new Exception("添加数据到表 wx_customerreplymsg 失败！");
/*     */         }
/*     */ 
/* 219 */         n = this.custIntratnChannelDAO.updateIntratnTimeById(date, id);
/* 220 */         if (n > 0) {
/* 221 */           DbConnection.commit();
/*     */         } else {
/* 223 */           DbConnection.rollback();
/* 224 */           throw new Exception("更新 custIntratnChannel 表失败！date=" + 
/* 225 */             date + " id=" + id);
/*     */         }
/*     */ 
/* 228 */         ResponseUtils.setSuccessResponse(response);
/* 229 */         return; }
/* 230 */       logger.error("上传失败,存在空数据：openName=" + openName + " openId=" + 
/* 231 */         openId + " msgType=" + msgType);
/*     */     }
/*     */     catch (Exception e) {
/* 234 */       DbConnection.rollback();
/* 235 */       logger.error("上传失败,事务异常:" + e.getMessage());
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.wxdownload.controller.WxDownLoad
 * JD-Core Version:    0.5.3
 */